package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogCelebrationFestiveChange;
import com.yanqu.road.entity.log.LogCelebrationFestiveCrossChange;
import com.yanqu.road.entity.log.LogCelebrationProcess;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Author cwq
 * @Data 2021/7/22 11:12
 */
public class LogCelebrationDaoImpl extends TempDao {

    public boolean addLogCelebrationProcessList(List<LogCelebrationProcess> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_celebration_process(activityId,userId,id,addScore,curValue,logTime) VALUES(?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogCelebrationProcess data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getAddScore()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getCurValue()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getLogTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogCelebrationFestiveChangeList(List<LogCelebrationFestiveChange> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_celebration_festive_change(activityId,addScore,curValue,info,logTime) VALUES(?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogCelebrationFestiveChange data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getAddScore()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getCurValue()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getInfo()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getLogTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogCelebrationFestiveCrossChangeList(List<LogCelebrationFestiveCrossChange> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getCrossDb());
        String sql = "INSERT INTO t_c_activity_celebration_festive_change_log(activityId,addScore,curValue,info,logTime) VALUES(?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogCelebrationFestiveCrossChange data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getAddScore()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getCurValue()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getInfo()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getLogTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

}
